﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="hy_liikmesusType_v3", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(HyLiikmesusTypeV3))]
    public class HyLiikmesusTypeV3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IHyLiikmesusTypeV3 clazz;
        
        public HyLiikmesusTypeV3Serializer(IHyLiikmesusTypeV3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("number");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Number))).ToString());
            Writer.WriteEndElement();
            if (clazz.Pindala!=null) {
                Writer.WriteStartElement("pindala");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Pindala))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Maksumaar!=null) {
                Writer.WriteStartElement("maksumaar");
                global::Xtee.Core.SerializationMetadata metaMaksumaar = this.GetMetaData(clazz.Maksumaar);
                Writer.WriteTypeAttribute(metaMaksumaar.TypeQualifiedName.Namespace, metaMaksumaar.TypeQualifiedName.Name);
                metaMaksumaar.NewSerializer(clazz.Maksumaar).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.HyKitsend != null) 
                        && (x < clazz.HyKitsend.Count)); x = (x + 1)) {
                if (clazz.HyKitsend[x]!=null) {
                    Writer.WriteStartElement("hy_kitsend");
                    global::Xtee.Core.SerializationMetadata metaHyKitsend = this.GetMetaData(clazz.HyKitsend[x]);
                    Writer.WriteTypeAttribute(metaHyKitsend.TypeQualifiedName.Namespace, metaHyKitsend.TypeQualifiedName.Name);
                    metaHyKitsend.NewSerializer(clazz.HyKitsend[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="number") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>hy_liikmesusType_v3>number");
                }
                clazz.Number = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("number")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>hy_liikmesusType_v3>number", Reader.LocalName);
            }
            if (Reader.LocalName=="pindala") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>hy_liikmesusType_v3>pindala");
                }
                clazz.Pindala = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("pindala")).Value;
            }
            if (Reader.LocalName=="maksumaar") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>hy_liikmesusType_v3>maksumaar");
                }
                global::Xtee.Core.SerializationMetadata metaMaksumaar = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMurdType>(Reader, "murdType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Maksumaar = metaMaksumaar.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMurdType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("maksumaar");
                    metaMaksumaar.NewSerializer(clazz.Maksumaar).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="hy_kitsend") {
                clazz.HyKitsend = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IKitsendusedTypeV3>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "hy_kitsend")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaHyKitsend = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IKitsendusedTypeV3>(Reader, "kitsendusedType_v3", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IKitsendusedTypeV3 item = metaHyKitsend.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IKitsendusedTypeV3>();
                        clazz.HyKitsend.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("hy_kitsend");
                            metaHyKitsend.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.HyKitsend.Add(null);
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
